//
//  MineWeatherCityListView.m
//  baodongPro
//
//  Created by feng on 16/3/4.
//  Copyright © 2016年 proper. All rights reserved.
//

#import "MineWeatherCityListView.h"
#import "UIView+FBDQuickCreateUI.h"
#import "WeatherCityModel.h"

@interface MineWeatherCityListView() <UITableViewDelegate,UITableViewDataSource>
{

}

@property(nonatomic,copy)void (^myTableIndexBlock)(NSInteger index);
@end

@implementation MineWeatherCityListView
{
    UITableView*_cityTableView;
}

-(instancetype)initWithFrame:(CGRect)frame
{

    self=[super initWithFrame:frame];
    if (self)
    {

        
        _cityTableView=[self fbd_quickCreateUITabdWithleViewFrame:CGRectMake(ScreenW/3.0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame)) andDelegateAndDataSource:self];
        _cityTableView.backgroundColor=[UIColor whiteColor];
        _backGroundView=[self fbd_quickCreateUIViewWithFrame:CGRectMake(0, 0, ScreenW, CGRectGetHeight(frame))];
        _backGroundView.backgroundColor=[UIColor blackColor];
        _backGroundView.alpha=0.6;
        [self addSubview:_backGroundView];
        
        
        UILabel* tipLabel=[self fbd_quickCreateUILabelWithFrame:CGRectMake(0, 0, ScreenW, 60)];
        tipLabel.backgroundColor=[UIColor whiteColor];
        tipLabel.text=@"                查看过的纪录";
        _cityTableView.tableHeaderView=tipLabel;
        
        [self addSubview:_cityTableView];
        self.backgroundColor=[UIColor whiteColor];
    }
    
    
    return self;
}
-(void)setCityListArray:(NSMutableArray *)cityListArray
{
    _cityListArray=cityListArray;
    [_cityTableView reloadData];
    
    
}


#pragma mark  UITableViewDelegate&&UITableViewDataSource


#pragma mark ---UITableViewDataSource&&UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _cityListArray.count;
//    return 20;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* indetifier=@"MyCells";
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:indetifier];
    if (!cell)
    {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetifier];
        cell.backgroundColor=[cell randomColor];
        cell.selectionStyle=0;
    }
    
    NSInteger row=indexPath.row;
    WeatherCityModel* everyModel=[_cityListArray objectAtIndex:row];
    cell.textLabel.text=everyModel.m_userTip;

    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    NSInteger row=indexPath.row;
    
    if (_myTableIndexBlock) {
        _myTableIndexBlock(row);
    }
    
    

    NSLog(@"点击了 cell for indexpatch ：%ld",indexPath.row);





}
/**
 *      @author 冯宝东
 *
 *      带有block 回调的构造方法
 *
 *      @param frame   大小位置
 *      @param myblcok block 回调
 *
 *      @return 实例对象
 */
-(instancetype)initWithFrame:(CGRect)frame withClickedIndexBlcok:(void(^)(NSInteger index))myblcok
{
    self=[self initWithFrame:frame];

    
    if (self&&myblcok)
    {
        self.myTableIndexBlock=myblcok;
    }


    return self;
}













@end
